package service

import (
	"fmt"
	"github.com/docker/docker/client"
	"time"
)

// ConnectDocker
// 链接docker
func ConnectDocker(ip string, apiPort string) (dockerCli *client.Client, err error) {
	host := "tcp://" + ip + ":" + apiPort
	dockerCli, err = client.NewClientWithOpts(client.WithAPIVersionNegotiation(), client.WithHost(host), client.WithTimeout(200*time.Millisecond))
	if err != nil {
		fmt.Println(err)
		return dockerCli, err
	}
	return dockerCli, nil
}

func ConnectDockerForWebsocket(ip string, apiPort string) (dockerCli *client.Client, err error) {
	host := "tcp://" + ip + ":" + apiPort
	dockerCli, err = client.NewClientWithOpts(client.WithAPIVersionNegotiation(), client.WithHost(host))
	if err != nil {
		fmt.Println(err)
		return dockerCli, err
	}
	return dockerCli, nil
}
